package com.pactera.madp.cp.controller.sidebar.medium;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.medium.MediumAddDTO;
import com.pactera.madp.cp.api.vo.medium.MediumGroupVO;
import com.pactera.madp.cp.service.IMediumGroupService;
import com.pactera.madp.cp.service.IMediumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * MediumWeChatController
 *
 * @author jun
 * @version 1.0
 * 2021/6/29 10:35
 **/
@RestController
@AllArgsConstructor
@RequestMapping("/mediumwechat")
@Api(value = "mediumwechat", tags = "话术库-微信")
public class MediumWeChatController {

    private IMediumService mediumServiceImpl;
    private IMediumGroupService mediumGroupServiceImpl;

    /**
     * @description:分组列表
     * @return:
     * @author: Huayu
     * @time: 2020/12/7 15:18
     */
    @GetMapping("/group_list")
    @ApiOperation(value = "话术库分组列表")
    public R<List<MediumGroupVO>> mediumGroupIndex(String wxUserId) {
        return R.ok(mediumGroupServiceImpl.getMediumGroupListWeChat(wxUserId));
    }

    /**
     * @description: 列表
     * @return:
     * @author: Huayu
     * @time: 2020/12/7 13:21
     */
    @GetMapping("/page")
    @ApiOperation(value = "话术库列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mediumGroupId",value="话术素材组id",dataType ="String"),
    })
    public R<IPage> mediumIndex(String searchStr, Integer type, String wxUserId, String mediumGroupId, Page page) {
        // 默认查1-文本
        if (type == null) {
            type = 1;
        }
        return R.ok(mediumServiceImpl.mediumPageWeChat(searchStr, type, wxUserId, mediumGroupId, page));
    }

    /**
     * @description: 添加素材库
     * @return:
     * @author: Huayu
     * @time: 2020/12/7 14:23
     */
    @SysLog("新建话术库素材")
    @PostMapping
    @ApiOperation(value = "新建话术库素材")
    public R<Boolean> mediumStore(@RequestBody MediumAddDTO dto){
        return mediumServiceImpl.insertAllBatchWeChat(dto) ?R.ok(Boolean.TRUE,"新增成功"):R.failed(Boolean.FALSE,"新增失败");
    }

    @SysLog("发送话术素材")
    @GetMapping("/send")
    @ApiOperation(value = "发送话术素材")
    public R sendMedium(Integer id){
        return mediumServiceImpl.sendMedium(id);
    }

}
